//
//  CommonView.swift
//  DragonWallet
//
//  Created by volantPig on 2024/2/21.
//

import UIKit

class CommonView: NSObject {

}

class JDSelectedInfoView: UIView {
    
    /// 选中索引 -1: 未选择
    var selectedIdx: Int = -1
    
    private var titleLabel: UILabel?
    private var contentLabel: UILabel?
    private var rightArrow: UIImageView?
    var control: UIControl?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupUIElements()
        self.layer.cornerRadius = 8
        self.backgroundColor = .white
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUIElements() {
        
        self.titleLabel = UILabel()
        self.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self).offset(12)
            make.centerY.equalTo(self)
        })
        self.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        self.titleLabel?.textColor = .init(hexString: "#333333")
        
        self.contentLabel = UILabel()
        self.addSubview(self.contentLabel!)
        self.contentLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self).offset(103)
            make.centerY.equalTo(self)
        })
        self.contentLabel?.font = UIFont.systemFont(ofSize: 15, weight: .regular)
        self.contentLabel?.textColor = .init(hexString: "#333333")
        
        self.rightArrow = UIImageView()
        self.addSubview(self.rightArrow!)
        self.rightArrow?.snp.makeConstraints({ make in
            make.right.equalTo(self).offset(-26)
            make.centerY.equalTo(self)
            make.size.equalTo(CGSize(width: 11, height: 11))
        })
        self.rightArrow?.image = UIImage(named: "arrow_black")?.withRenderingMode(.alwaysOriginal)
        
    }
    
    func setContentInfo(_ contentStr: String?) {
        self.contentLabel?.text = contentStr
    }
    
    func refreshTextInfo(_ title: String,_ placeholder: String) {
        self.contentLabel?.text = placeholder
        self.titleLabel?.text = title
    }
    
}


class JDInputInfoView: UIView {

    private var titleLabel: UILabel?
    private var inputTF: UITextField?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupUIElements()
        self.layer.cornerRadius = 8
        self.backgroundColor = .white
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUIElements() {
        
        self.titleLabel = UILabel()
        self.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self).offset(12)
            make.centerY.equalTo(self)
        })
        self.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        self.titleLabel?.textColor = .init(hexString: "#333333")
        
        self.inputTF = UITextField()
        self.addSubview(self.inputTF!)
        self.inputTF?.snp.makeConstraints({ make in
            make.left.equalTo(self).offset(103)
            make.top.equalTo(self).offset(5)
            make.bottom.equalTo(self).offset(-5)
            make.right.equalTo(self).offset(-10)
        })
        self.inputTF?.font = UIFont.systemFont(ofSize: 15, weight: .regular)
        self.inputTF?.textColor = .init(hexString: "#333333")
        
    }
    
    func refreshTextInfo(_ title: String,_ placeholder: String) {
        self.inputTF?.placeholder = placeholder
        self.titleLabel?.text = title
    }
 
    func inputStr() -> String {
        self.inputTF?.text ?? ""
    }
    
}

class JDSwitchView: UIView {

    private var titleLabel: UILabel?
    private var switchButton: UISwitch?
    private var switchTitleLabel: UILabel?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupUIElements()
        self.layer.cornerRadius = 8
        self.backgroundColor = .white
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUIElements() {
        
        self.titleLabel = UILabel()
        self.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self).offset(12)
            make.centerY.equalTo(self)
        })
        self.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        self.titleLabel?.textColor = .init(hexString: "#333333")
        
        self.switchButton = UISwitch()
        self.addSubview(self.switchButton!)
        self.switchButton?.snp.makeConstraints({ make in
            make.right.equalTo(self).offset(-24)
            make.centerY.equalTo(self)
            make.size.equalTo(CGSizeMake(48, 28))
        })
        self.switchButton?.onTintColor = color("#FA6161")
        self.switchButton?.thumbTintColor = .white
        
        self.switchTitleLabel = UILabel()
        self.addSubview(self.switchTitleLabel!)
        self.switchTitleLabel?.snp.makeConstraints({ make in
            make.centerY.equalTo(self)
            make.right.equalTo(self.switchButton!.snp.left).offset(-8)
        })
        self.switchTitleLabel?.text = "启用"
        self.switchTitleLabel?.labelConfig(textAlignment: .right, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"))
    }
    
    func refreshTextInfo(_ title: String,_ switchTitle: String) {
        self.switchTitleLabel?.text = switchTitle
        self.titleLabel?.text = title
    }
    
    func getSwitchSate() -> Bool {
        return self.switchButton?.isOn ?? false
    }
 
}
